import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Font;

import ulj2me.*;

public class JFrmPage2 extends JULFrame implements IAudioListner
{
	protected JULMenu m_Menu;
	JULList m_list;
	JULCombo m_combo;
	JULDate m_date;
	JULBtn m_btnRec,m_btnStop,m_btnPlay;
	JULHyperLink m_hypLink;
	byte CMD_LNK=20;
	
	JULFontVect m_fontVect;
	
	JULAudio m_Audio;
	//JULScrollBox m_ScrollBox;

	
	public JFrmPage2()
	{
		super();
		m_fontVect=new JULFontVect();
		m_Audio=new JULAudio(this);
	}
	//========================================
	public void OnCreate()
	{

		super.OnCreate();		

		m_btnRec=new JULBtn();
		m_btnRec.CreateWnd(this,0,0,0,JULWorkSpace.GetLogUnit());
		m_btnRec.SetText("Rec");
		m_btnRec.FitToText();
		m_btnStop=new JULBtn();
		m_btnStop.CreateWnd(this,0,0,0,JULWorkSpace.GetLogUnit());
		m_btnStop.SetText("Stop");
		m_btnStop.FitToText();
		m_btnPlay=new JULBtn();
		m_btnPlay.CreateWnd(this,0,0,0,JULWorkSpace.GetLogUnit());
		m_btnPlay.SetText("Play");
		m_btnPlay.FitToText();
		
		m_combo=new JULCombo();
		m_combo.CreateWnd(this,0,0,0,0);
		m_combo.ReadOnly(true);
		m_combo.Add("1");
		m_combo.Add("2");
		m_combo.Add("3");
		m_combo.Add("4");
		m_combo.Add("5");
		m_combo.Add("6");
		

		m_date=new JULDate();
		m_date.CreateWnd(this,0,0,0,0);
		m_date.SetYearRange(1950,1995);
		m_date.Set(9,2,1983);




		m_list=new JULList();
		m_list.CreateWnd(this,0,0,0,0);
		for(int i=0;i<7;++i)
			m_list.Add("long text long text long text long text"+i);

		m_hypLink=new JULHyperLink();
		m_hypLink.CreateWnd(this,0,0,0,0);
		m_hypLink.SetText("link");
		m_hypLink.SetCmd(CMD_LNK);
		m_hypLink.SetLink("http://forum.sources.ru");
		
		
		m_Menu=new JULMenu();
		m_Menu.Create(this);
		m_Menu.SetKeyText(JULMenu.LEFTKEY,"Menu");
		m_Menu.SetKeyText(JULMenu.RIGHTKEY,"Next");
		m_Menu.EnableMinMaxBtn(true);

		
		EnableScroll(JULScroll.VERT,true);
		SetScrollStep(JULWorkSpace.GetLogUnit());				
	}
	public void OnSize(int w,int h)
	{
		super.OnSize(w,h);

		int nY=JULWorkSpace.GetLogUnit();
		
		m_btnRec.SetPos(10,nY,70,JULWorkSpace.GetLogUnit(),
			SWP_MOVE|SWP_REDRAW|SWP_NOTIFY);
		m_btnStop.SetPos(70,nY,70,JULWorkSpace.GetLogUnit(),
			SWP_MOVE|SWP_REDRAW|SWP_NOTIFY);
		m_btnPlay.SetPos(140,nY,70,JULWorkSpace.GetLogUnit(),
			SWP_MOVE|SWP_REDRAW|SWP_NOTIFY);
		

		nY+=JULWorkSpace.GetLogUnit()*10;
		m_combo.SetPos(10,nY,m_rectWnd.cx-20,JULWorkSpace.GetLogUnit(),
			SWP_MOVE|SWP_SIZE|SWP_REDRAW|SWP_NOTIFY);
		m_combo.SetMinVisible(4);


		nY=JULWorkSpace.GetLogUnit()*5;

		m_date.SetPos(10,nY,200,JULWorkSpace.GetLogUnit(),
			SWP_MOVE|SWP_SIZE|SWP_REDRAW|SWP_NOTIFY);
		m_date.SetMinVisible(4);


		nY+=JULWorkSpace.GetLogUnit()*2*4;
		m_list.SetPos(10,nY,m_rectWnd.cx-20,JULWorkSpace.GetLogUnit()*5,
			SWP_MOVE|SWP_SIZE|SWP_REDRAW|SWP_NOTIFY);




		nY+=JULWorkSpace.GetLogUnit()*6*4;			
		m_hypLink.SetPos(10,nY,150,JULWorkSpace.GetLogUnit(),
			SWP_MOVE|SWP_SIZE|SWP_REDRAW|SWP_NOTIFY);

			
		SetVirtualSize(m_rectWnd.cx,nY+JULWorkSpace.GetLogUnit()*3);
			
	}
	public void OnCmd(JULWnd wndSender,byte nType)
	{
		if(JFrmMain.IsMainMsg(nType))
			return;

		if(nType==CMD_LNK)
		{
			System.out.println("CMD_LNK");
			return;
		}
		
		if(nType==MN_LEFTKEY)
		{
			JULPopupMenu pmenu=new JULPopupMenu();
			pmenu.Create(this);

			JFrmMain.FillVertMenu(pmenu);

			JULPoint pt=JULWorkSpace.GetScreenSize();
			int y=pt.y;
			if(m_Menu.IsOpen())
				y-=JULWorkSpace.GetLogUnit();
			pmenu.Track(0,y,JULPopupMenu.TOPRIGHT);			
		}
		if(nType==MN_RIGHTKEY)
		{
			Destroy();
			m_frmOwner.OnCmd(this,JFrmMain.N_PAGE3);
		}
		
		if(wndSender==m_btnRec)
		{
			m_Audio.Record();
			return;
		}
		if(wndSender==m_btnPlay)
		{
			m_Audio.Play();
			return;
		}
		if(wndSender==m_btnStop)
		{
			m_Audio.Stop();
			return;
		}
		super.OnCmd(wndSender,nType);
	}
	public void OnPaint(Graphics g)
	{
		super.OnPaint(g);
		g.setColor(0,0,0);
		m_fontVect.SetSize(2*JULWorkSpace.GetLogUnit()/3);
		m_fontVect.SetStyle(JULFontVect.NORMAL);
		m_fontVect.DrawString(g,"Any text",10,200);
	}
	//================================
	public void OnElapsedTime(int nSec)
	{
		System.out.println("time:"+nSec);		
	}
	public void OnStop()
	{
		System.out.println("OnStop:"+m_Audio.GetBuffer().length);
	}
}